package plus.xj17520.org.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import plus.xj17520.annotation.MyLog;
import plus.xj17520.org.domain.Employee;
import plus.xj17520.org.service.IEmplService;
import plus.xj17520.base.query.EmplQuery;
import plus.xj17520.base.result.JSONResult;

/**
 * @projectName: pethomeProject
 * @package: plus.xj17520.org.controller
 * @className: EmplController
 * @author: XiaoJue
 * @description: TODO
 * @date: 2022/5/23 14:51
 * @version: 1.0
 */
@RestController
@RequestMapping("empl")
@Api(value = "员工管理的接口文档",description = "员工管理的接口文档")
public class EmplController {
    @Autowired
    IEmplService emplService;

    @ApiOperation(value = "查询单个员工对象",notes = "此方法的具体说明在这里描述")
    @GetMapping("findOne/{id}")
    public JSONResult findOne(@ApiParam(value = "员工id") @PathVariable Long id){
        return emplService.findOne(id);
    }

    @ApiOperation(value = "查询员工的所有对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("all")
    public JSONResult findAll(){
        return emplService.findAll();
    }

    @ApiOperation(value = "新增一个员工对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("add")
    public JSONResult add(@RequestBody Employee employee){
        return emplService.addOrUpdate(employee);
    }

    @ApiOperation(value = "删除一个员工对象",notes = "此方法的具体说明在这里描述")
    @MyLog(title = "员工模块", content = "删除员工操作")
    @GetMapping("delete/{id}")
    public JSONResult delete(@ApiParam(value = "员工实例对象的id") @PathVariable Long id){
        return emplService.delete(id);
    }

    @ApiOperation(value = "修改一个员工对象",notes = "此方法的具体说明在这里描述")
    @PostMapping("update")
    public JSONResult update(@RequestBody Employee employee){
        return emplService.addOrUpdate(employee);
    }

    @ApiOperation(value = "分页，高级查询",notes = "此方法的具体说明在这里描述")
    @PostMapping("query")
    public JSONResult query(@RequestBody EmplQuery emplQuery){
        return emplService.emplPageList(emplQuery);
    }

    @ApiOperation(value = "批量删除",notes = "此方法的具体说明在这里描述")
    @PostMapping("batchDelete")
    public JSONResult batchDelete(@RequestBody EmplQuery emplQuery){
        return emplService.batchDelete(emplQuery);
    }
}
